var t = require("../../../utils/function.js"), e = require("../../../api.js"), a = getApp();

Page({
    data: {
        total_price: '',
        estimated_form_time:'',
        is_online_price: "",
        dingshi: "",
        latitude: "",
        license_plate_num:'',
        longitude: "",
        // 司机
        avatar_url:'',
        real_name:'',
        work_phone:'',
        graded: '',
        // 司机
        img: t.userImg,
        markers: [],
        polyline: [ {
            points: [],
            color: "#0299de",
            width: 9,
            dottedLine: !1,
            arrowLine: !0
        } ],
        controls: [ {
            id: 1,
            // iconPath: "../../../images/user/icon-22.png",
            // position: {
            //     left: 10,
            //     top: 10,
            //     width: 50,
            //     height: 50
            // },
            clickable: !0
        }, {
            id: 2,
            // iconPath: "../../../images/user/icon-30.png",
            // position: {
            //     top: 280,
            //     left: 10,
            //     width: 50,
            //     height: 50
            // },
            clickable: !0
        } ],
        driver: {},
        order_going_s: 0,
        order_going_m: 0,
        startAddress: null,
        myShow: !0,
        zuoyou: "icon-zuoyou",
        avatar: "../../../images/user/icon-07.png",
        buttonText: "登录",
        username: "未登录",
        orderGoing: !1,
        homeHandlerShow: !0,
        phone: "",
        order_no: "",
        is_service: 1,
        initiate: 0,
        left_width: 680,
        target_adds: "",
        time: ""
    },
    regionchange: function(t) {
        console.log(t.type);
    },
    markertap: function(t) {
        console.log(t.markerId);
    },
    controltap: function(e) {
        var a = this;
        if (console.log("map controltap", e.controlId), 1 === e.controlId) wx.navigateTo({
            url: "/pages/map/my/my"
        }); else t.getLatLntHandler(function(t) {
            a.setData({
                startAddress: t.startAddress
            });
        });
    },
    getPolyline: function(t, e) {
        var a = this, n = wx.getStorageSync("MAP_KEY"), o = this.data.polyline, i = t.latitude + "," + t.longitude + "&to=" + e.latitude + "," + e.longitude ,p = '&policy=LEAST_DISTANCE';
        console.log("correct", t, "error", e), wx.request({
            url: "https://apis.map.qq.com/ws/direction/v1/driving/?from=" + i + "&key=" + n + p,
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                if (384 != t.data.status) {
                    for (var e = t.data.result.routes[0].polyline, n = 2; n < e.length; n++) e[n] = e[n - 2] + e[n] / 1e6;
                    for (var i = [], s = 0; s < e.length; s += 2) i[i.length] = {
                        longitude: e[s + 1],
                        latitude: e[s]
                    };
                    o[0].points = i, a.setData({
                        polyline: o
                    });
                }
            },
            fail: function() {}
        });
    },
    openMyPageHandler: function() {
        var t = this.data, e = (t.pageRight, t.myShow);
        e ? this.setData({
            pageRight: 620,
            left_width: 130,
            myShow: !e,
            controls: [ {
                id: 1,
                iconPath: "../../../images/user/icon-33.png",
                position: {
                    top: 144,
                    left: 10,
                    width: 41,
                    height: 41
                },
                clickable: !0
            } ]
        }) : (this.setData({
            pageRight: 0,
            left_width: 750,
            myShow: !e,
            controls: [ {
                id: 1,
                // iconPath: "../../../images/user/icon-22.png",
                // position: {
                //     left: 10,
                //     top: 10,
                //     width: 50,
                //     height: 50
                // },
                clickable: !0
            }, {
                id: 2,
                // iconPath: "../../../images/user/icon-30.png",
                // position: {
                //     top: 280,
                //     left: 10,
                //     width: 50,
                //     height: 50
                // },
                clickable: !0
            } ]
        }), this.changeIcon());
    },
    deleteOrderHandler: function() {
        wx.showToast({
            title: "订单正在进行中，无法删除订单",
            icon: "none"
        });
    },
    onlineServerHandler: function(e) {
        t.callPhoneHandler(e.currentTarget.dataset.phone);
    },
    onLoad: function(t) {
        this.setData({
            order_no: t.order_no
        }), t.uid && a.shareCouponsMessage(t.uid);
    },
    intoPaidHandler: function(t) {
        wx.navigateTo({
            url: t.currentTarget.dataset.url
        });
    },
    onShow: function() {
        var n = this;
        a.request({
            url: e.order.isOnlinePrice,
            method: "post",
            data: {},
            success: function(t) {
                1 == t.code && (n.setData({
                    is_online_price: t.data.is_online_price
                }), 1 == t.data.is_online_price ? (n.startReportHearts(), n.postionTask(1)) : n.postionTask(0));
            }
        }), "" !== wx.getStorageSync("userMessage") && this.setData({
            avatar: wx.getStorageSync("userMessage").avatar,
            username: wx.getStorageSync("userMessage").username,
            buttonText: wx.getStorageSync("userMessage").buttonText,
            phone: wx.getStorageSync("phonep")
        }), t.getLatLntHandler(function(t) {
            n.setData({
                startAddress: {
                    location: {
                        lat: t.location.lat,
                        lng: t.location.lng
                    }
                }
            });
        }), this.changeIcon();
    },
    startReportHearts: function() {
        var t = this, e = this.data.polyline, n = setInterval(function() {
            e[0].points = a.driver_position, t.setData({
                longitude: a.longitudes,
                latitude: a.latitudes,
                polyline: e
            });
        }, 1e3);
        this.setData({
            dingshi: n
        });
    },
    callPolice: function() {
        wx.makePhoneCall({
            phoneNumber: "110"
        });
    },
    postionTask: function(t) {
        var n = this;
        a.request({
            url: e.order.setout,
            method: "post",
            data: {
                order_no: n.data.order_no
            },
            success: function(e) {
            var p =    e.data.diver.real_name
                p =   p.substring(0, 1)
                1 == e.code && (wx.setStorageSync("startAddress", e.data.slang), wx.setStorageSync("endAddress", e.data.elang), 
                n.setData({
                    startAddress: e.data.elang,
                    markers: e.data.start_location,
                    is_service: e.data.is_service,
                    initiate: e.data.initiate,
                    driver: e.data.diver,
                    target_adds: e.data.target_adds,
                    serverphone: e.data.serverphone,
                    signature: e.data.diver.signature,
                    estimated_form_time:e.data.estimated_form_time,
                    total_price:e.data.total_price,
                    // 司机
                    avatar_url:e.data.diver.avatar_url,
                    real_name:p,
                    work_phone:e.data.diver.work_phone,
                    graded: e.data.diver.graded,
                    license_plate_num:e.data.diver.license_plate_num

                }), 0 == t && n.getPolyline(e.data.s_location[0], e.data.s_location[1]));
            }
        });
    },
    loginHandler: function(e) {
        var a = this;
        "登录" === this.data.buttonText ? t.loginHandler(function(e) {
            a.setData({
                res: e
            });
            wx.showModal({
                title: "获取手机号码",
                content: "我们需要获取你的电话号码，一边与和你保持实时的联系，防止你的订单丢失",
                success: function(e) {
                    e.confirm && t.intoPageHandler("../../user/getPhone/getPhone");
                },
                fail: function() {
                    wx.showToast({
                        title: "登录失败",
                        icon: "none"
                    });
                }
            });
        }) : this.setData({
            avatar: "../../../images/user/icon-07.png",
            username: "未登录",
            buttonText: "登录",
            phone: ""
        });
    },
    intoPageHandler: function(e) {
        t.intoPageHandler(e.currentTarget.dataset.skip);
    },
    callPhoneHandler: function() {
        t.callPhoneHandler(wx.getStorageSync("serverPhone"));
    },
    changeIcon: function() {
        var t = this, e = this.data.controls;
        wx.getSystemInfo({
            success: function(a) {
                var n = a.windowWidth / 750 * 390, o = a.windowHeight - n;
                console.log(a, "2222222222"), e[1] = {
                    id: 2,
                    // iconPath: "../../../images/user/icon-30.png",
                    // position: {
                    //     top: o - 56,
                    //     left: 10,
                    //     width: 50,
                    //     height: 50
                    // },
                    clickable: !0
                }, t.setData({
                    winPath: {
                        w: a.windowWidth,
                        h: a.windowHeight
                    },
                    map_height: o / 1.5 ,
                    controls: e
                });
            }
        });
    },
    onUnload: function() {
        1 == this.data.is_online_price && clearInterval(this.data.dingshi);
    },
    onHide: function() {},
    onShareAppMessage: function() {
        var t = a.shareAppMessage().title, e = a.shareAppMessage().imageUrl, n = a.shareAppMessage().desc, o = a.shareAppMessage().path;
        return console.log(a.shareAppMessage()), {
            title: t,
            imageUrl: e,
            desc: n,
            path: o
        };
    }
});